<?php 
if ((isset($_POST["host"])) && $_POST["host"] && $_POST["user"]) {
	$path = str_replace("\\",'/',getcwd());
	$path = substr(substr($path,0,-1), 0, strrpos($path,"/"));

	$html_path = substr(substr($_SERVER["REQUEST_URI"],0,-1), 0, strrpos($_SERVER["REQUEST_URI"],"/"));
	$html_path = substr(substr($html_path,0,-1), 0, strrpos($html_path,"/"));

	$fp = fopen("../config.php","w+");
	fwrite($fp, '<?php
	$HOST = "'.$_POST["host"].'";
	$USER = "'.$_POST["user"].'";
	$PASS = "'.$_POST["pass"].'";
	$DB = "'.$_POST["db"].'";

	global $ROOT;
	$ROOT = "'.$path.'/";
	global $ROOT_HTML;
	$ROOT_HTML = "'.$html_path.'/";

	global $MYSQL_PREFIX;
	$MYSQL_PREFIX = "'.$_POST["prefix"].'";
	?>' . PHP_EOL);
	fclose($fp);
	header("location: index.php?stage=3");
} else {
	include("stage2_style.php");
}
?>